package cloudbus

import "zstackgo/pkg/header/message"

var (
	_ CloudBusListCallBack = new(CloudBusListCallBackImpl[any])
)

type CloudBusListCallBack interface {
	Run(replies []*message.MessageReply)
}

type CloudBusListCallBackImpl[T any] struct {
	backups []T
	fn      func([]*message.MessageReply)
}

func NewCloudBusListCallBackImpl[T any](fn func([]*message.MessageReply), one T, others ...T) *CloudBusListCallBackImpl[T] {
	i := &CloudBusListCallBackImpl[T]{
		fn: fn,
	}

	i.backups = append(i.backups, one)
	if len(others) > 0 {
		i.backups = append(i.backups, others...)
	}

	return i
}

func (impl *CloudBusListCallBackImpl[T]) Run(replies []*message.MessageReply) {
	impl.fn(replies)
}
